{% extends 'admin/base.html' %}

{% block title %}仪表盘 - 管理后台{% endblock %}
{% block page_title %}仪表盘{% endblock %}

{% block content %}
<div class="row">
    <!-- 统计卡片 -->
    <div class="col-md-6 col-lg-3 mb-4">
        <div class="card stats-card">
            <div class="card-body text-center">
                <i class="bi bi-bicycle display-4 mb-3"></i>
                <div class="stats-number">{{ total_bikes }}</div>
                <div>本学院自行车总数</div>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3 mb-4">
        <div class="card stats-card">
            <div class="card-body text-center">
                <i class="bi bi-exclamation-triangle display-4 mb-3 text-warning"></i>
                <div class="stats-number">{{ pending_violations }}</div>
                <div>待处理违章</div>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3 mb-4">
        <div class="card stats-card">
            <div class="card-body text-center">
                <i class="bi bi-clock-history display-4 mb-3 text-info"></i>
                <div class="stats-number">{{ processing_violations }}</div>
                <div>处理中违章</div>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3 mb-4">
        <div class="card stats-card">
            <div class="card-body text-center">
                <i class="bi bi-check-circle display-4 mb-3 text-success"></i>
                <div class="stats-number">{{ resolved_violations }}</div>
                <div>已处理违章</div>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-3 mb-4">
        <div class="card stats-card">
            <div class="card-body text-center">
                <i class="bi bi-list-ul display-4 mb-3 text-primary"></i>
                <div class="stats-number">{{ total_violations }}</div>
                <div>违章总数</div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <!-- 最近添加的自行车 -->
    <div class="col-md-6 mb-4">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="bi bi-clock-history"></i> 最近添加的自行车
                </h5>
            </div>
            <div class="card-body">
                {% if recent_bikes %}
                <div class="table-responsive">
                    <table class="table table-sm">
                        <thead>
                            <tr>
                                <th>编号</th>
                                <th>所有人</th>
                                <th>型号</th>
                                <th>时间</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for bike in recent_bikes %}
                            <tr>
                                <td>
                                    <span class="badge bg-primary">{{ bike.bike_number }}</span>
                                </td>
                                <td>{{ bike.owner_name }}</td>
                                <td>{{ bike.model }}</td>
                                <td>
                                    <small class="text-muted">{{ bike.created_at|date:"m-d H:i" }}</small>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="text-center">
                    <a href="{% url 'bike:admin_bike_list' %}" class="btn btn-outline-primary btn-sm">
                        查看全部
                    </a>
                </div>
                {% else %}
                <div class="text-center py-4">
                    <i class="bi bi-bicycle display-4 text-muted"></i>
                    <p class="text-muted mt-2">暂无自行车记录</p>
                    <a href="{% url 'bike:admin_bike_add' %}" class="btn btn-primary">
                        <i class="bi bi-plus-circle"></i> 添加第一辆自行车
                    </a>
                </div>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- 最近的违章记录 -->
    <div class="col-md-6 mb-4">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="bi bi-exclamation-triangle"></i> 最近的违章记录
                </h5>
            </div>
            <div class="card-body">
                {% if recent_violations %}
                <div class="table-responsive">
                    <table class="table table-sm">
                        <thead>
                            <tr>
                                <th>自行车</th>
                                <th>类型</th>
                                <th>状态</th>
                                <th>时间</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for violation in recent_violations %}
                            <tr>
                                <td>
                                    <span class="badge bg-secondary">{{ violation.bicycle.bike_number }}</span>
                                </td>
                                <td>{{ violation.get_violation_type_display }}</td>
                                <td>
                                    {% if violation.status == 'pending' %}
                                    <span class="badge bg-warning">待处理</span>
                                    {% elif violation.status == 'processing' %}
                                    <span class="badge bg-info">处理中</span>
                                    {% elif violation.status == 'resolved' %}
                                    <span class="badge bg-success">已解决</span>
                                    {% else %}
                                    <span class="badge bg-secondary">已撤销</span>
                                    {% endif %}
                                </td>
                                <td>
                                    <small class="text-muted">{{ violation.created_at|date:"m-d H:i" }}</small>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="text-center">
                    <a href="{% url 'bike:violation_list' %}" class="btn btn-outline-primary btn-sm">
                        查看全部
                    </a>
                </div>
                {% else %}
                <div class="text-center py-4">
                    <i class="bi bi-check-circle display-4 text-success"></i>
                    <p class="text-muted mt-2">暂无违章记录</p>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 快速操作 -->
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="bi bi-lightning"></i> 快速操作
                </h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3 mb-2">
                        <a href="{% url 'bike:admin_bike_add' %}" class="btn btn-success w-100">
                            <i class="bi bi-plus-circle"></i> 添加自行车
                        </a>
                    </div>
                    <div class="col-md-3 mb-2">
                        <a href="{% url 'bike:admin_bike_list' %}" class="btn btn-primary w-100">
                            <i class="bi bi-list-ul"></i> 管理自行车
                        </a>
                    </div>
                    <div class="col-md-3 mb-2">
                        <a href="{% url 'bike:violation_list' %}" class="btn btn-warning w-100">
                            <i class="bi bi-exclamation-triangle"></i> 违章记录
                        </a>
                    </div>
                    <div class="col-md-3 mb-2">
                        <a href="{% url 'bike:export_qr_codes' %}" class="btn btn-info w-100">
                            <i class="bi bi-download"></i> 导出二维码
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
